package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveRewardGoods;
import com.jhgsys.internal.incentive.service.IIncentiveRewardGoodsService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励物品 Controller
 *
 * @author wanghjw
 * @date 2024-09-03 14:08:29
 */
@Slf4j
@Validated
@Controller
public class IncentiveRewardGoodsController extends BaseController {

    @Autowired
    private IIncentiveRewardGoodsService incentiveRewardGoodsService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardGoods")
    @RequiresPermissions("incentiveRewardGoods:view")
    public String incentiveRewardGoodsIndex(){
        return FebsUtil.view("incentive/incentiveRewardGoods/incentiveRewardGoodsList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardGoods/add")
    @RequiresPermissions("incentiveRewardGoods:add")
    public String incentiveRewardGoodsAdd(){
        return FebsUtil.view("incentive/incentiveRewardGoods/incentiveRewardGoodsEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveRewardGoods/update/{id}")
    @RequiresPermissions("incentiveRewardGoods:edit")
    public String incentiveRewardGoodsUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveRewardGoods", incentiveRewardGoodsService.findIncentiveRewardGoodsById(id));
        return FebsUtil.view("incentive/incentiveRewardGoods/incentiveRewardGoodsEdit");
    }

    /**
     * 查询（所有）
     * @author wanghjw
     * @date 2024-09-03 14:08:29
     */
    @GetMapping("incentiveRewardGoods")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:view")
    public FebsResponse getAllIncentiveRewardGoodss(IncentiveRewardGoods incentiveRewardGoods) {
        return new FebsResponse().success().data(incentiveRewardGoodsService.findIncentiveRewardGoodsList(incentiveRewardGoods));
    }

    /**
     * 查询（分页）
     * @author wanghjw
     * @date 2024-09-03 14:08:29
     */
    @GetMapping("incentiveRewardGoods/list")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:view")
    public FebsResponse incentiveRewardGoodsList(QueryRequest request, IncentiveRewardGoods incentiveRewardGoods) {
        Map<String, Object> dataTable = getDataTable(this.incentiveRewardGoodsService.findIncentiveRewardGoodsPage(request, incentiveRewardGoods));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveRewardGoods
     * @author wanghjw
     * @date 2024-09-03 14:08:29
     */
    @Log("新增IncentiveRewardGoods")
    @PostMapping("incentiveRewardGoods")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:add")
    public FebsResponse addIncentiveRewardGoods(@Valid IncentiveRewardGoods incentiveRewardGoods) throws FebsException {
        try {
            incentiveRewardGoods.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveRewardGoodsService.createIncentiveRewardGoods(incentiveRewardGoods);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveRewardGoods失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveRewardGoods
     * @author wanghjw
     * @date 2024-09-03 14:08:29
     */
    @Log("逻辑删除IncentiveRewardGoods")
    @GetMapping("incentiveRewardGoods/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:delete")
    public FebsResponse deleteIncentiveRewardGoods(@PathVariable("id") String incentiveRewardGoodsIds) throws FebsException {
        try {
            IncentiveRewardGoods incentiveRewardGoods = new IncentiveRewardGoods();
            incentiveRewardGoods.setDeletedBy(getCurrentUser().getUserName());
            incentiveRewardGoods.setDeletedTime(new Date());
            incentiveRewardGoods.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveRewardGoodsService.deleteIncentiveRewardGoods(incentiveRewardGoods,incentiveRewardGoodsIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardGoods失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveRewardGoods
    * @author wanghjw
    * @date 2024-09-03 14:08:29
    */
    @Log("物理删除IncentiveRewardGoods")
    @GetMapping("incentiveRewardGoods/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:delete")
    public FebsResponse physicallyDeleteIncentiveRewardGoods(@PathVariable("id") String incentiveRewardGoodsIds) throws FebsException {
        try {
            this.incentiveRewardGoodsService.physicallyDeleteIncentiveRewardGoods(incentiveRewardGoodsIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveRewardGoods失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveRewardGoods
     * @author wanghjw
     * @date 2024-09-03 14:08:29
     */
    @Log("修改IncentiveRewardGoods")
    @PostMapping("incentiveRewardGoods/update")
    @ResponseBody
    @RequiresPermissions("incentiveRewardGoods:edit")
    public FebsResponse updateIncentiveRewardGoods(IncentiveRewardGoods incentiveRewardGoods) throws FebsException {
        try {
            incentiveRewardGoods.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveRewardGoodsService.updateIncentiveRewardGoods(incentiveRewardGoods);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveRewardGoods失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
